using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using FBGraph.Demos.AspNetMvc.Models.View.Profile;
using FBGraph.Models;

namespace FBGraph.Demos.AspNetMvc.Controllers
{
    public class ProfileController : BaseController
    {
        public ActionResult Detail(Object id)
        {
            using (FbContext.StartAsync())
            {
                var user = FbContext.Users.Get(id);
                var feed = FbContext.Users.Feed.GetFor(id, 5);
                var posts = FbContext.Users.Posts.GetFor(id, 5);
                var tagged = FbContext.Users.Tagged.GetFor(id, 5);
                var activities = FbContext.Users.Activities.GetFor(id, 5);
                var interests = FbContext.Users.Interests.GetFor(id, 5);
                var music = FbContext.Users.Music.GetFor(id, 5);
                var books = FbContext.Users.Books.GetFor(id, 5);
                var movies = FbContext.Users.Movies.GetFor(id, 5);
                var television = FbContext.Users.Television.GetFor(id, 5);
                var likes = FbContext.Users.Likes.GetFor(id, 5);
                var photos = FbContext.Users.Photos.GetFor(id, 10);
                var albums = FbContext.Users.Albums.GetFor(id, 5);
                var videos = FbContext.Users.Videos.GetFor(id, 3);
                var groups = FbContext.Users.Groups.GetFor(id, 10);
                var statuses = FbContext.Users.Statuses.GetFor(id, 5);
                var links = FbContext.Users.Links.GetFor(id, 5);
                var notes = FbContext.Users.Notes.GetFor(id, 5);
                var events = FbContext.Users.Events.GetFor(id, 5);

                PagedResult<Post> home = null;
                PagedResult<User> friends = null;
                PagedResult<MailboxItem> inbox = null;
                PagedResult<MailboxItem> outbox = null;
                PagedResult<MailboxItem> updates = null;
                if (id.Equals(FbContext.UserID))
                {
                    home = FbContext.Users.Home.GetFor(id);
                    friends = FbContext.Users.Friends.GetFor(id);
                    inbox = FbContext.Users.Inbox.GetFor(id);
                    outbox = FbContext.Users.Outbox.GetFor(id);
                    updates = FbContext.Users.Outbox.GetFor(id);
                }

                FbContext.CompleteAsync();

                var model = new DetailData
                {
                    Activities= activities,
                    Albums = albums,
                    Books = books,
                    Events = events,
                    Feed = feed,
                    Friends = friends,
                    Groups = groups,
                    Home = home,
                    Inbox = inbox,
                    Interests = interests,
                    Likes = likes,
                    Links = links,
                    Movies = movies,
                    Music = music,
                    Notes = notes,
                    Outbox = outbox,
                    Photos = photos,
                    Posts = posts,
                    Statuses = statuses,
                    Tagged = tagged,
                    Television = television,
                    Updates = updates,
                    User = user,
                    Videos = videos
                };

                return View(model);
            }
        }
    }
}